package model.custom;

import common.RoomTypes;
import model.booking.Booking;
import java.time.LocalDate;
import java.util.List;

/**
 * 客户类
 */
public class Custom {
    private String name;    //客户姓名
    private String contactInformation; //联系方式（电话号码）
    private String idNumber;  //身份证号
    private boolean membership; //会员(true:是会员，false:不是会员)
    private List<Booking> bookingHistory; //预约历史

    public Custom(String name, String contactInformation, String idNumber, boolean membership) {
        this.name = name;
        this.contactInformation = contactInformation;
        this.idNumber = idNumber;
        this.membership = membership;
    }

    //预约
    public void makeAReservation(String name, LocalDate checkInTime , int duration, RoomTypes roomTypes){
        if(name.trim().isEmpty()) {
            System.out.println("姓名不能为空");
            return;
        }
        if(duration <= 0) {
            System.out.println("住房持续时间必须为正数");
            return;
        }
        String room = getRoomId(roomTypes);
        double price = getPrice(roomTypes);
        //Booking reservation = new Booking(name, checkInTime, duration, room, price);
        //bookingHistory.add(reservation);   // 添加到预约历史
    }
    //获取将要住的房间号 //有重复问题 后续修改//循环遍历房间 查看空？ 加入参数
    private String getRoomId(RoomTypes roomTypes) {
        String str;
        switch (roomTypes) {
            case Single_ROOM:
                for(int i=1;i<=30;i++){
                    if(isRoomAvailable("A"+i)){
                        str="A"+i;
                        break;
                    }
                }
            case Twin_ROOM:
                for(int i=1;i<=30;i++){
                    if(isRoomAvailable("B"+i)){
                        str="B"+i;
                        break;
                    }
                }
            case Double_ROOM:
                for(int i=1;i<=30;i++){
                    if(isRoomAvailable("C"+i)){
                        str="C"+i;
                        break;
                    }
                }
            case Deluxe_ROOM:
                for(int i=1;i<=30;i++){
                    if(isRoomAvailable("D"+i)){
                        str="D"+i;
                        break;
                    }
                }
            default:
                System.out.println("无效的选择，请重新选择");
                return getRoomId(roomTypes);
        }
    }
    //获取预定的房间价格
    private double getPrice(RoomTypes roomType) {
        switch (roomType) {
            case Single_ROOM:   //单人房
                return 100.0;
            case Twin_ROOM:     //双人房
                return 150.0;
            case Double_ROOM:   //大床房
                return 200.0;
            case Deluxe_ROOM:   //豪华大床房
                return 399.0;
            default:
                return -1;
        }
    }
    //查看自己的预约历史
    public List<Booking> reservationHistory(){
        if(bookingHistory.isEmpty() || bookingHistory == null){
            System.out.println("对不起，您在本酒店没有预约记录");
            return null;
        }else{
            return bookingHistory;
        }
    }
    //入住 修改->调用Check....它的
    public void cheakIn(){

    }
    //退房 修改->调用Check....它的
    public void cheakOut(){

    }
    //续住
//    public void extendStay(int duration){   //传参:续住时间
//        String roomId = getRoomId();   //有问题/房间号
//        if (!isRoomAvailable(roomId)) {
//            System.out.println("房间已占用，无法续住！");
//        }else{
//            //更新住房记录信息:有问题，目前将记录放在预定记录里，且checkInTime需修改
//            LocalDate checkInTime = new LocalDate();
//            Booking reservation = new Booking(name, checkInTime, duration,roomId, getPrice(roomId));
//            bookingHistory.add(reservation);  //添加记录
//        }
//    }
    //验证房间是否可用
    private boolean isRoomAvailable(String roomId) {
        //检查房间状态、日期
        return true;
    }
}
